package cn.ycc1.storage.service.impl;

import cn.ycc1.storage.mapper.StorageMapper;
import cn.ycc1.storage.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Title:
 * @Author ycc
 * @Date 2023/7/4 15:36
 */
@Service
@Slf4j
public class StorageServiceImpl implements StorageService {
    @Autowired
    StorageMapper storageMapper;

    @Override
    @Transactional
    public void deduct(String code, Integer count) {
        log.info("开始扣减库存");
        try {
            storageMapper.deduct(code, count);
        } catch (Exception e) {
            throw new RuntimeException("扣减库存失败，可能是库存不足！", e);
        }
        log.info("扣减库存成功");
    }
}
